package main

import (
	"fmt"
	"math"
	"sort"
)

type Shape interface {
	Area() float64
	Name() string
}

// 圆形
type Circle struct {
	Radius float64
}

func (c Circle) Area() float64 {
	return math.Pi * math.Pow(c.Radius, 2)
}

func (c Circle) Name() string {
	return "Circle"
}

// 三角形
type Triangle struct {
	Base, Height float64
}

func (t Triangle) Area() float64 {
	return (t.Base * t.Height) / 2
}

func (t Triangle) Name() string {
	return "Triangle"
}

// 矩形
type Rectangle struct {
	Width, Height float64
}

func (r Rectangle) Area() float64 {
	return r.Width * r.Height
}

func (r Rectangle) Name() string {
	return "Rectangle"
}

// 按面积降序排列
func sortShapesByAreaDescending(shapes []Shape) {
	sort.Slice(shapes, func(i, j int) bool {
		return shapes[i].Area() > shapes[j].Area()
	})
}

func main() {
	shapes := []Shape{
		Circle{Radius: 5.0},
		Triangle{Base: 4.0, Height: 3.0},
		Rectangle{Width: 6.0, Height: 2.0},
		Circle{Radius: 2.5},
		Triangle{Base: 6.0, Height: 4.0},
	}
	sortShapesByAreaDescending(shapes)
	fmt.Println("排列后：")
	for _, shape := range shapes {
		fmt.Printf("%s: %.2f\n", shape.Name(), shape.Area())
	}
}
